{extend name="platform/base" /} 
{block name="resources"/}
<style>
.active>.text-active {
    display: inline-block !important;
}
.text-active, .active>.text {
    display: none;
}
</style>

{/block}

{block name="main"}
<header class="header clearfix">
	<div class="row m-t-sm">
		<a href="PLATFORM_MAIN/System/addModule?pid=0"
			class="btn btn-sm btn-primary"><i class="fa fa-plus"></i> 添加模块</a>
	</div>
</header>
<section class="panel panel-default">
	<table class="table table-striped b-t b-light text-sm">
		<thead>
			<tr>
				<th width="10"></th>
				<th width="80">排序</th>
				<th>模块名</th>
				<th class="center">是否是菜单</th>
				<th class="center" width="100">操作</th>
			</tr>
		</thead>
		<tbody>
			{foreach name="list" item="v1"}
			<tr class="pid_0" style="height: 30px;">
				<td>{if condition="$v1['sub_menu'] neq array()"}<a
					href="javascript:;" onclick="tab_switch({$v1['module_id']})"
					class="tab_jia_{$v1['module_id']}" style="display: block;"> <i
						class="fa fa-plus"></i></a> <a href="javascript:;"
					onclick="tab_switch({$v1['module_id']})"
					class="tab_jian_{$v1['module_id']}" style="display: none;"><i
						class="fa fa-minus"></i></a> {/if}
				</td>
				<td><input type="text" class="form-control"
					fieldid="{$v1['module_id']}" fieldname="sort" value="{$v1['sort']}"
					size="1"></td>
				<td>
					<div class="col-md-12">
						<input type="text" class="form-control"
							fieldid="{$v1['module_id']}" fieldname="module_name"
							value="{$v1['module_name']}">
					</div>
				</td>

				<td class="center"><a href="#"
					class="{$v1['is_menu'] ? 'active' : ''}" data-toggle="class"
					onclick="changeField({$v1['module_id']}, 'is_menu', {$v1['is_menu'] ? 0 : 1});"><i
						class="fa fa-check text-success text-active"></i><i
						class="fa fa-times text-danger text"></i></a></td>
				<td class="center"><a
					href="{:__URL('PLATFORM_MAIN/System/editModule?module_id='.$v1['module_id'])}"
					title="修改">修改</a> <a href="javascript:void(0);"
					onclick="delModule({$v1['module_id']})">删除</a></td>
			</tr>
			{foreach name="v1['sub_menu']" item="v2"}
			<tr class="pid_{$v1['module_id']}" style="display: none;">
				<td>{if condition="$v2['sub_menu'] neq array()"}<a
					href="javascript:void(0)" onclick="tab_switch({$v2['module_id']})"
					class="tab_jian_{$v2['module_id']} tab_jian_{$v1['module_id']}"
					style="display: block;"><i class="fa fa-minus"></i></a><a
					href="javascript:void(0)" onclick="tab_switch({$v2['module_id']})"
					class="tab_jia_{$v2['module_id']} tab_jia_{$v1['module_id']}"
					style="display: none;"><i class="fa fa-plus"></i></a> {/if}
				</td>
				<td><input type="text" class="form-control "
					fieldid="{$v2['module_id']}" fieldname="sort" value="{$v2['sort']}"
					size="1"></td>
				<td>
					<div class="col-md-1"></div>
					<div class="col-md-11">
						<input type="text" class="form-control"
							fieldid="{$v2['module_id']}" fieldname="module_name"
							value="{$v2['module_name']}">
					</div>
				</td>
				<!--<th>控制器名</th>
									<th>方法名</th>
									<th>url</th>-->
				<!--<td>{$v2['is_menu'] ? '是' : '否'}</td>
						<td>{$v2['is_menu'] ? '是' : '否'}</td>-->
				<td class="center"><a href="#"
					class="{$v2['is_menu'] ? 'active' : ''}" data-toggle="class"
					onclick="changeField({$v2['module_id']}, 'is_menu', {$v2['is_menu'] ? 0 : 1});"><i
						class="fa fa-check text-success text-active"></i><i
						class="fa fa-times text-danger text"></i></a></td>
				<td class="center"><a
					href="{:__URL('PLATFORM_MAIN/System/editModule?module_id='.$v2['module_id'])}"
					title="修改">修改</a> <a href="javascript:void(0);"
					onclick="delModule({$v2['module_id']})">删除</a></td>
			</tr>
			{foreach name="v2['sub_menu']" item="v3"}
			<tr class="pid_{$v2['module_id']} pid_{$v1['module_id']}"
				style="display: none;">
				<td><label></td>
				<td><input type="text" class="form-control"
					fieldid="{$v3['module_id']}" fieldname="sort" value="{$v3['sort']}"
					size="1"></td>
				<td>
					<div class="col-md-2"></div>
					<div class="col-md-10">
						<input type="text" fieldid="{$v3['module_id']}"
							class="form-control" fieldname="module_name"
							value="{$v3['module_name']}">
					</div>
				</td>
				<!--<th>控制器名</th>
									<th>方法名</th>
									<th>url</th>-->
				<!--<td>{$v3['is_menu'] ? '是' : '否'}</td>
						<td>{$v3['is_menu'] ? '是' : '否'}</td>-->
				<td class="center"><a href="#"
					class="{$v3['is_menu'] ? 'active' : ''}" data-toggle="class"
					onclick="changeField({$v3['module_id']}, 'is_menu', {$v3['is_menu'] ? 0 : 1});"><i
						class="fa fa-check text-success text-active"></i><i
						class="fa fa-times text-danger text"></i></a></td>
				<td class="center"><a
					href="{:__URL('PLATFORM_MAIN/System/editModule?module_id='.$v3['module_id'])}"
					title="修改">修改</a> <a href="javascript:void(0);"
					onclick="delModule({$v3['module_id']})">删除</a></td>
			</tr>
			{foreach name="v3['sub_menu']" item="v4"}
			<tr
				class="pid_{$v3['module_id']} pid_{$v2['module_id']} pid_{$v1['module_id']}"
				style="display: none;">
				<td><label></td>
				<td><input type="text" class="form-control"
					fieldid="{$v4['module_id']}" fieldname="sort" value="{$v4['sort']}"
					size="1"></td>
				<td>
					<div class="col-md-3"></div>
					<div class="col-md-9">
						<input type="text" fieldid="{$v4['module_id']}"
							class="form-control" fieldname="module_name"
							value="{$v4['module_name']}">
					</div>
				</td>
				<td class="center"><a href="#"
					class="{$v4['is_menu'] ? 'active' : ''}" data-toggle="class"
					onclick="changeField({$v4['module_id']}, 'is_menu', {$v4['is_menu'] ? 0 : 1});"><i
						class="fa fa-check text-success text-active"></i><i
						class="fa fa-times text-danger text"></i></a></td>
				<td class="center"><a
					href= "{:__URL('PLATFORM_MAIN/System/editModule?module_id='.$v4['module_id'])}"
					title="修改">修改</a> <a href="javascript:void(0);"
					onclick="delModule({$v4['module_id']})" title="删除">删除</a></td>
			</tr>
			{foreach name="v4['sub_menu']" item="v5"}
			<tr
				class="pid_{$v4['module_id']} pid_{$v3['module_id']} pid_{$v2['module_id']} pid_{$v1['module_id']}"
				style="display: none;">
				<td><label></td>
				<td><input type="text" class="form-control"
					fieldid="{$v5['module_id']}" fieldname="sort" value="{$v5['sort']}"
					size="1"></td>
				<td>
					<div class="col-md-4"></div>
					<div class="col-md-8">
						<input type="text" fieldid="{$v5['module_id']}"
							class="form-control" fieldname="module_name"
							value="{$v5['module_name']}">
					</div>
				</td>
				<td class="center"><a href="#"
					class="{$v5['is_menu'] ? 'active' : ''}" data-toggle="class"
					onclick="changeField({$v5['module_id']}, 'is_menu', {$v5['is_menu'] ? 0 : 1});"><i
						class="fa fa-check text-success text-active"></i><i
						class="fa fa-times text-danger text"></i></a></td>
				<td class="center"><a
					href="{:__URL('PLATFORM_MAIN/System/editModule?module_id='.$v5['module_id'])}"
					title="修改">修改</a> <a href="javascript:void(0);"
					onclick="delModule({$v5['module_id']})">删除</a></td>
			</tr>
			{/foreach} {/foreach} {/foreach} {/foreach} {/foreach}
		</tbody>
	</table>
</section>

<input type="hidden" id="pid" value="0" />
{include file="platform/openDialog" /}
<script type="text/javascript">
$("table input").change(function(){
	var fieldid = $(this).attr('fieldid');
	var fieldname = $(this).attr('fieldname');
	var fieldvalue = $(this).val();
	changeField(fieldid, fieldname, fieldvalue);
});
function changeField(fieldid, fieldname, fieldvalue){
	$.ajax({
		type:"post",
		url:"{:__URL('PLATFORM_MAIN/system/modifyfield')}",
		data:{'fieldid':fieldid,'fieldname':fieldname,'fieldvalue':fieldvalue},
		async:true,
		success: function (data) {
			if(data['code'] <= 0){
				showMessage('error',data['message']);
			}
		}
	});
}
	function tab_switch(module_id){
		if($(".pid_"+module_id).css('display') != 'none'){
			$(".tab_jian_"+module_id).hide();
			$(".tab_jia_"+module_id).show();
			$(".pid_"+module_id).hide(300);
		}else{
			$(".tab_jian_"+module_id).show();
			$(".tab_jia_"+module_id).hide();
			$(".pid_"+module_id).show(500);
		}
	}
		function delModule(module_id){
			$( "#dialog" ).dialog({
	            buttons: {
	                "确定,#e57373": function() {
	                    $(this).dialog('close');
	                    $.ajax({
	        				type:"post",
	        				url:"{:__URL('PLATFORM_MAIN/system/delmodule')}",
	        				data:{'module_id':module_id},
	        				async:true,
	        				success:function (data) {
	        					if(data['code'] > 0){
	        						location.href = "{:__URL('PLATFORM_MAIN/system/modulelist')}";
	        					}else{
	        						$("#dialog").dialog({
	        							 buttons: {
	        					                "确定,#e57373": function() {
	        					                    $(this).dialog('close');
	        					                }
	        					            },
	        					            contentText:data['message']
	        						})
	        					}
	        				}
	        			});
	                },
	                "取消": function() {
	                    $(this).dialog('close');
	                }
	            },
	            contentText:"确定删除？",
	        });
		}
        </script>
{/block}
